package com.irdstudio.rsp.rule.api.rest;

import com.irdstudio.rsp.rule.service.facade.BizRuleAdapterService;
import com.irdstudio.rsp.rule.service.vo.BizRuleAdapterVO;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.beans.web.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class BizRuleAdapterController extends AbstractController  {
	
	@Autowired
	@Qualifier("bizRuleAdapterServiceImpl")
	private BizRuleAdapterService bizRuleAdapterService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/biz/rule/adapters", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<BizRuleAdapterVO>> queryBizRuleAdapterAll(
			BizRuleAdapterVO vo) {		
		List<BizRuleAdapterVO> outputVo = bizRuleAdapterService.queryAllOwner(vo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/biz/rule/adapter/{recordKeyid}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<BizRuleAdapterVO> queryByPk(@PathVariable("recordKeyid") String recordKeyid) {		
		BizRuleAdapterVO inVo = new BizRuleAdapterVO();
				inVo.setRecordKeyid(new String(recordKeyid));
		BizRuleAdapterVO outputVo = bizRuleAdapterService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param bizRuleAdapter
	 * @return
	 */
	@RequestMapping(value="/biz/rule/adapter", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody BizRuleAdapterVO inBizRuleAdapterVo) {
		try {
			int outputVo = bizRuleAdapterService.deleteByPk(inBizRuleAdapterVo);
			return getResponseData(outputVo);
		} catch(Exception e) {
			return getResponseData(-1);
		}

	}
	
	/**
	 * 根据主键更新信息
	 * @param inBizRuleAdapterVo
	 * @return
	 */
	@RequestMapping(value="/biz/rule/adapter", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody BizRuleAdapterVO inBizRuleAdapterVo) {		
		try {
			int outputVo = bizRuleAdapterService.updateByPk(inBizRuleAdapterVo);
			return getResponseData(outputVo);
		} catch(Exception e) {
			return getResponseData(-1);
		}
	}
	
	/**
	 * 新增数据
	 * @param inBizRuleAdapterVo
	 * @return
	 */
	@RequestMapping(value="/biz/rule/adapter", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertBizRuleAdapter(@RequestBody BizRuleAdapterVO inBizRuleAdapterVo) {
		try {
			int outputVo = bizRuleAdapterService.insertBizRuleAdapter(inBizRuleAdapterVo);
			return getResponseData(outputVo);
		} catch(Exception e) {
			return getResponseData(-1);
		}
	}
}
